<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="css/style.css" />
<link type="text/css" rel="stylesheet" href="css/layout.css" />
<title>Quản lý chuyên mục !</title>
</head>

<body>
<?php include("menu.php");
include("../include/config.php"); ?>





<div id="head-noidung">


	<div id="head-main">
<?php
$id=$_REQUEST["id"];
$sql="SELECT * FROM subcategory WHERE id=$id";
$rs=mysql_query($sql);
if ($rs)
	$rw=mysql_fetch_array($rs);
else
	die('Truy vấn sai!');
?>
	<form name="subcategoryedit" action="" method="get">
	<table class="classtable" style="width:45%;">
	<tbody">
	<tr>
	<td>Tên chuyên mục</td>
	<td><input name="subcategory" type="text" size="35" style="float:left;" value="<?php echo $rw['name'];?>"></td>
	</tr>
	
	<tr>
	<td>Số thứ tự</td>
	<td><input name="sttsubcategory" type="text" size="5" style="float:left;" value="<?php echo $rw['stt'];?>"></td>
	</tr>
		
	<tr>
	<td>Category</td>
	<td>
	
		
	<select name="category_id">
	<?php 
	$sql2="SELECT * FROM category ORDER By id";
	$rs2=mysql_query($sql2);
	if($rs2) {
		while($rw2=mysql_fetch_array($rs2)) {
		?>
			<option value="<?php echo $rw2['id']?>"> <?php echo $rw2['name']?></option>
			<?php $parent_id=$rw2['id']?> 
			
		<?php
		}
	}
	?>

	<select>
	
	
</td>
	
	</tr>
	

	
	
	<tr>
	<td>Hoạt động</td>
	
	<td> 	<select name="status">
				<option value="1" <?php echo ($rw['status'] == 1)?"selected='selected'":""?>> Hiện </option>
				<option value="0" <?php echo ($rw['status'] == 0)?"selected='selected'":""?>> Ẩn </option>
			</select></td> 
	
	</tr>
	<tr>
	<td></td>
	<td><input type="submit" name="subcategoryedit" value="CapNhat"/>
	<input type="hidden" name="id" value="<?php echo $id?>" />

	
	</td>
	</tr>
	
	</tbody>
	</table>
	</form>
	
		<?php 
	 if(isset($_REQUEST["subcategoryedit"]))
	 {
	 	$category=$_REQUEST["subcategory"];
		$stt=$_REQUEST["sttsubcategory"];
		$id=$_REQUEST["id"];
		$status=$_REQUEST["status"];
		$parent_id=$_REQUEST["category_id"];
		$sql2="UPDATE subcategory
				SET name='" . addslashes($category) . "'
					,stt=$stt
					,status=$status
					,parent_id=$parent_id
				WHERE
					id=$id";
					
		mysql_query($sql2);
		
		if($status	==1) {
		$sql4="UPDATE product SET status=1 WHERE category=$id";
		mysql_query($sql4);
		}
		else {
		$sql5="UPDATE product SET status=0 WHERE category=$id";
		mysql_query($sql5);
		}
			
		echo ("Cập nhật thành công");
?> <a class="copyrighta" href="category.php">Trở lại danh sách</a>
<?php } ?>
		</div>	
</div>

<?php include("images/cherry/footer.php"); ?>

</body>
</html>
